home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / mem / MPW Helpers / Procedures / fmacunix.icn < prev    next >
Encoding:
Text File  |  1992-11-08  |  800 b   |  39 lines  |  [TEXT/MPS ]

  1. procedure FileNameUnixToMac(fn)
  2.   local newfn,p,full
  3.   if not find("/",fn) then return fn
  4.   newfn := ""
  5.   if full := match("/",fn) then fn[1] := ""
  6.   fn ? until pos(0) do {
  7.     p := tab(find("/") | 0)
  8.     newfn ||:= case p of {
  9.       "" | ".": ""
  10.       "..": ":"
  11.       default: ":" || p
  12.     }
  13.     move(1)
  14.   }
  15.   if newfn[-1] == ":" then newfn ||:= ":"
  16.   else if fn[-1] == "/" then newfn ||:= ":"
  17.   if \full then newfn[1] := ""
  18.   return newfn
  19. end
  20.  
  21.  
  22. procedure FileNameMacToUnix(fn)
  23.   local newfn
  24.   if not find(":",fn) then return fn
  25.   if fn[1] == ":" then {
  26.     fn[1] := ""
  27.     newfn := ""
  28.   }
  29.   else newfn := "/"
  30.   fn ? until pos(0) do {
  31.     while move(1) == ":" do newfn ||:= "../"
  32.     if pos(0) then break
  33.     newfn ||:= tab(find(":") | 0) || "/"
  34.     move(1)
  35.   }
  36.   newfn[-1] := ""
  37.   return newfn
  38. end
  39.